import { Router } from "express"
import { IcallbackFn, Ioracle } from "../../types"

export default (router: Router, oracle: Ioracle, callbackFn: IcallbackFn) => {
  router.post("/mailResult", (req, res) => {
    const { queryDate,orgCode,backupResult } = req.body
    let sql = " select * from xx_server_manage_schedule "
    sql += " where sdate = to_date('"+ queryDate +"','yyyy-mm-dd') "
    if(orgCode)
      sql += " and org_code = '"+ orgCode +"' "
    if(backupResult)
      sql += " and nvl(backup_result,'EMPTY') = '"+ backupResult +"' "
    sql += " order by org_code,nvl(backup_desc,0) "
    callbackFn(res, oracle.connCcapps, { sql })
  })

  router.post("/getServerName",(_req,res) => {
    let sql = " select distinct org_code,server_name "
    sql += " from xx_server_manage_header "
    callbackFn(res, oracle.connCcapps, { sql })
  })

  return router
}
